import java.io.FileInputStream;
import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.util.List;
import java.util.Properties;
import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.output.*;
import java.rmi.RemoteException;


/**
 *
 * @author Alejandro Figueroa
 */
public class Interfaz extends javax.swing.JFrame{

    // <editor-fold defaultstate="collapsed" desc="Variables">

    private AccesoRemoto server;

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructores">

    public Interfaz() {

        initComponents();
        Properties props = new Properties();

        try
        {
            props.load(new FileInputStream("tanque.properties"));
            jLabel1.setText("Tanque "+props.getProperty("numeroPropio"));
            setTitle("Visualizar Tanque "+props.getProperty("numeroPropio"));

        }catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("Error al tratar de acceder al archivos de propiedades o al "
                    + "tratar de imprimir por pantalla");
        }
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Codigo Generado">

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        activar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Visualizar Tanque 2");

        activar.setText("Activar Tanque");
        activar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                activarMouseClicked(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 36)); // NOI18N
        jLabel1.setText("Tanque 2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(143, 143, 143)
                        .addComponent(activar)))
                .addContainerGap(114, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(35, 35, 35)
                .addComponent(activar)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Evento del Boton">

    private void activarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_activarMouseClicked

        // Se inicializar el tanque a traves de acceso Remoto
        try
        {
            server = new AccesoRemoto();

            if (!server.registrarServicio())
                System.exit(1);
        }
        catch (Exception e)
        {
            System.out.println(e);
        }

        //desabilitamos la ventana en curso
        this.setVisible(false);

    }//GEN-LAST:event_activarMouseClicked

    // </editor-fold>

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interfaz().setVisible(true);
            }

        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton activar;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
